/**
 * Created by Yixin on 2017/8/21.
 */
define([
    "app"
],
function (app) {
   app.controller("manageRegisterDialogController",[
       "$scope",
       "team",
       "$uibModalInstance",
       "manageRegisterDataService",
       "$state",
       function ($scope,team,$uibModalInstance,manageRegisterDataService,$state) {
           $scope.team = team;
           $scope.requestRootUrl = requestRootUrl;

           $scope.dismiss = function () {
               $uibModalInstance.dismiss();
           };

           // 同意申请
           $scope.agree = function () {
               if(confirm("您确定要同意该申请吗?\n同意申请后会发送邮件通知团队入驻。")) {
                   manageRegisterDataService.agreeRegistration(team.teamId)
                       .then(function (resp) {
                           alert("修改成功!");
                           // 关闭窗口
                           $uibModalInstance.dismiss();
                           // 刷新页面
                           $state.go($state.current,{},{reload:true});
                       });
               }
           };

           // 退回申请
           $scope.refuse = function () {
               if(confirm("您确定要退回该申请吗?\n团队将会收到被退回的通知。")) {
                   manageRegisterDataService.refuseRegistration(team.teamId)
                       .then(function (resp) {
                           alert("修改成功");
                           // 关闭窗口
                           $uibModalInstance.dismiss();
                           // 刷新页面
                           $state.go($state.current,{},{reload:true});
                       });
               }
           }
   }]);
});